<template>
  <div id="activeManagementSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="人审结果" prop="manual">
          <el-select v-model="formInline.manual" clearable placeholder="请选择">
            <el-option
              v-for="item in manualList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机审结果" prop="machine">
          <el-select
            v-model="formInline.machine"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in machineList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排序规则" prop="sort">
          <el-select v-model="formInline.sort" placeholder="请选择">
            <el-option
              v-for="item in sortList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动分类" prop="tags">
          <el-select v-model="formInline.tags" clearable placeholder="请选择">
            <el-option
              v-for="item in tagsList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动名称" prop="activityId">
          <el-input
            clearable
            v-model="formInline.activityId"
            placeholder="请输入活动名称搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="内容查询" prop="content">
          <el-input
            clearable
            v-model="formInline.content"
            placeholder="请输入文字内容查询"
          ></el-input>
        </el-form-item>
        <el-form-item label="帖子类型" prop="contentType">
          <el-select
            v-model="formInline.contentType"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in postList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="timeType">
          <el-select v-model="formInline.timeType" placeholder="">
            <el-option
              v-for="item in timeTypeList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="时间线" prop="timeLine">
          <el-select v-model="formInline.timeLine" placeholder="请选择">
            <el-option
              v-for="item in timeLineList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="checkUserId">
          <el-select
            clearable
            filterable
            v-model="formInline.checkUserId"
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in personList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户搜索" prop="userType">
          <el-select v-model="formInline.userType" placeholder="请选择">
            <el-option
              v-for="item in searchList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="userValue">
          <el-input
            clearable
            v-model="formInline.userValue"
            placeholder="请输入相应的搜索内容"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户属性" prop="userProperty">
          <el-select v-model="formInline.userProperty" clearable>
            <el-option
              v-for="item in userAttList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { getDpNum } from '@/api/system/user'
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'ActiveManagementSearch',
  msg: '通知管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          manual: '',
          machine: '',
          sort: '',
          tags: '',
          activityId: '',
          content: '',
          contentType: '',
          timeType: '',
          userType: '',
          timeLine: '',
          checkUserId: '',
          userValue: '',
          userProperty: '', // 用户属性
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      createTime: [], // 创建时间
      // 人审结果
      manualList: [
        { key: '全部', value: '' },
        { key: '未审核', value: 'NONE' },
        { key: '通过', value: 'PASSED' },
        { key: '未通过', value: 'REJECTED' }
      ],
      // 机审结果
      machineList: [
        { key: '全部', value: '' },
        { key: '通过', value: 'PASSED' },
        { key: '未通过', value: 'REJECTED' }
      ],
      // 排序
      sortList: [
        { key: '创建时间正序', value: 'createdDate asc' },
        { key: '创建时间倒序', value: 'createdDate desc' },
        { key: '机审时间正序', value: 'machineAuditTime asc' },
        { key: '机审时间倒序', value: 'machineAuditTime desc' }
      ],
      // 活动分类
      tagsList: [{ dictLabel: '全部', dictValue: '' }],
      // 排序2
      timeTypeList: [
        { key: '帖子发布时间', value: 'publishTime' },
        { key: '机审时间', value: 'machineTime' }
      ],
      // 帖子类型
      postList: [{ dictLabel: '全部', dictValue: '' }],
      // 时间线
      timeLineList: [],
      // 审核人
      personList: [{ nickname: '全部', dapengUserId: '' }],
      // 用户搜索
      searchList: [{ key: '大鹏号', value: 'DAPENGACCOUNT' }],
      userAttList: [{ dictLabel: '全部', dictValue: '' }] // 用户属性
    }
  },
  mounted() {
    this.getStickList()
    this.getTopSearch()
  },
  methods: {
    // 获取审核人
    getStickList() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
    },
    // 获取顶部搜索条件
    async getTopSearch() {
      // 获取活动帖子时间线
      this.timeLineList = await sysNormalDisable('sys_post_time')
      // 获取活动分类
      const tags = await sysNormalDisable('activity_type', 'activityCategory')
      this.tagsList = this.tagsList.concat(tags)
      // 获取活动帖子内容类型
      const post = await sysNormalDisable('sys_posts_type', 'contentType')
      this.postList = this.postList.concat(post)
      // 用户属性
      let UserAttr = await sysNormalDisable(
        'audit_user_property2',
        'activityAttr'
      )
      this.userAttList = this.userAttList.concat(UserAttr)
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.timeLine = this.timeLineList[0].dictValue
      this.formInline.timeType = this.timeTypeList[0].value
      this.formInline.sort = this.sortList[0].value
      this.formInline.userType = this.searchList[0].value
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
#activeManagementSearch {
  .el-input {
    &.el-input--suffix {
      width: 182px !important;
    }
  }
}
</style>
